package testCase;

import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.opentest4j.AssertionFailedError;

import java.util.logging.Logger;

public class BaseTestCase implements AfterEachCallback {
    Logger logger=Logger.getLogger(this.getClass().getName());
    @Override
    public void afterEach(ExtensionContext extensionContext) throws Exception {
        System.out.println("getDisplayName:"+extensionContext.getDisplayName());
        System.out.println("getUniqueId:"+extensionContext.getUniqueId());
        System.out.println("getTags:"+extensionContext.getTags().size());
        System.out.println("getParent:"+extensionContext.getParent());
        //可以获取用例执行过程中发生的异常
        //可以根据这个具体异常来操作重跑异常
        System.out.println("getExecutionException:"+extensionContext.getExecutionException().isPresent());
        if (extensionContext.getExecutionException().isPresent()){
            Throwable exception=extensionContext.getExecutionException().get();
            System.out.println("exception:"+exception);
            if (exception instanceof AssertionFailedError){
                    System.out.println("正常的断言失败");
            }else{
                System.out.println("准备重启");
            }
        }
    }
}
